package com.example.index.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.index.mapper.CollectMapper;
import com.example.index.service.ICollectService;
import com.yc.biz.BizException;

import com.yc.pojo.Collect;
import com.yc.util.Utils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxh
 * @since 2023-07-05
 */
@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements ICollectService {

    @Resource
    CollectMapper collectMapper;

    public void insertCollect(Integer userId, Integer houseId) throws BizException {
        Utils.checkEmpty(userId, "请登录后再收藏!");
        Utils.checkEmpty(houseId, "系统繁忙，请稍后重试!");
        Collect collect = new Collect();
        collect.setUserId(userId);
        collect.setHouseId(houseId);
        collectMapper.insert(collect);
    }

    public void deleteCollect(Integer userId, Integer houseId) throws BizException {
        Utils.checkEmpty(userId, "系统繁忙，请稍后重试!");
        Utils.checkEmpty(houseId, "系统繁忙，请稍后重试!");
        LambdaQueryWrapper<Collect> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Collect::getUserId,userId).eq(Collect::getHouseId,houseId);
        collectMapper.delete(lqw);
    }

}
